package at.horario.dao.hibernate;

import at.horario.dao.ChProfessorDao;
import at.horario.model.ChProfessor;
import at.horario.model.Ciclo;
import at.horario.model.Disciplina;
import org.hibernate.criterion.DetachedCriteria;
import static org.hibernate.criterion.DetachedCriteria.forClass;
import static org.hibernate.criterion.Restrictions.eq;

import java.util.List;

public class ChProfessorDaoHibernate extends GenericDaoHibernate<ChProfessor, Integer> implements ChProfessorDao {
    public ChProfessorDaoHibernate() {
        super(ChProfessor.class);
    }

    public ChProfessor find(Disciplina disciplina, Ciclo ciclo) {
        DetachedCriteria criteria = forClass(ChProfessor.class);
        criteria.add(eq("disciplina", disciplina));
        criteria.add(eq("ciclo", ciclo));
        List list = super.getHibernateTemplate().findByCriteria(criteria, 0, 1);
        return list.isEmpty() ? null : (ChProfessor) list.get(0);
    }
}